package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wechat.domain.Campsite;
import com.ruoyi.wechat.service.ICampsiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(value = "微信小程序API-营地营位管理", tags = {"微信小程序API-营地营位管理"})
@RestController
@RequestMapping("/wechat/campsite")
public class WxCampsiteController extends BaseController {
    @Autowired
    private ICampsiteService wxcampsiteService;

    /**
     * 按条件搜索营位列表
     * @param campsite 营位信息
     * @return 列表
     */
    @ApiOperation(value = "按条件搜索营位列表", response = Campsite.class)
    @GetMapping("/list")
    public AjaxResult list(Campsite campsite) {
        List<Campsite> list  = wxcampsiteService.selectCampsiteList(campsite);
        return success(list);
    }
    /**
     * 获取营地营位详细信息
     */
    @ApiOperation(value = "根据营位id获取详细信息", response = Campsite.class)
    @ApiParam(required = true, value = "直接传入id")
    @GetMapping(value = "/{campsiteId}")
    public AjaxResult getInfo(@PathVariable("campsiteId") String campsiteId)
    {
        return success(wxcampsiteService.selectCampsiteByCampsiteId(campsiteId));
    }
//    /**
//     * 新增营地营位
//     */
//    @ApiOperation(value = "新增营地营位")
//    @PostMapping
//    public AjaxResult add(@RequestBody Campsite campsite)
//    {
//        return toAjax(wxcampsiteService.insertCampsite(campsite));
//    }
    /**
     * 新增营地营位
     */
    @ApiOperation(value = "新增营地营位")
    @PostMapping
    public AjaxResult add(@RequestBody Campsite[] campsites)
    {
        return toAjax(wxcampsiteService.insertCampsites(campsites));
    }
    /**
     * 修改营地营位
     */
    @ApiOperation(value = "修改营地营位")
    @PutMapping
    public AjaxResult edit(@RequestBody Campsite campsite)
    {
        return toAjax(wxcampsiteService.updateCampsite(campsite));
    }

    /**
     * 删除营地营位
     */

    @ApiOperation(value = "删除营地营位")
    @DeleteMapping("/{campsiteIds}")
    public AjaxResult remove(@PathVariable String[] campsiteIds)
    {
        return toAjax(wxcampsiteService.deleteCampsiteByCampsiteIds(campsiteIds));
    }
}
